﻿using QDChat.Data;
using QDChat.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QDChat.Service
{
    public sealed class DataFactory
    {
        private static object _locker = new object();//锁对象
        private static IChatMessage _message = null;
        public static IChatMessage MessageInstance
        {
            get
            {
                if (_message == null)
                {
                    lock (_locker)
                    {
                        _message = new DbMessage();
                    }
                }
                return _message;
            }
        }

        private static IChatSession _session = null;
        public static IChatSession SessionInstance
        {
            get
            {
                if (_session == null)
                {
                    lock (_locker)
                    {
                        _session = new DbSession();
                    }
                }
                return _session;
            }
        }

        private static IChatUser _user = null;
        public static IChatUser UserInstance
        {
            get
            {
                if (_user == null)
                {
                    lock (_locker)
                    {
                        _user = new DbUser();
                    }
                }
                return _user;
            }
        }
    }
}
